﻿using System.Linq;
using System.Web.Mvc;
using Icms.Core.Model;
using Icms.Core.Service;
using Icms.WebUI.Builder;
using Icms.WebUI.Dto;
using Omu.Awesome.Mvc;

namespace Icms.WebUI.Controllers
{
    public class CaseTypeController : Cruder<CaseType, CaseTypeInput>
    {
        public CaseTypeController(ICrudService<CaseType> s, IMapper<CaseType, CaseTypeInput> v)
            : base(s, v)
        {
        }

        public virtual ActionResult Search(string search, int page = 1, int ps = 5)
        {
            var src = s.Where(o => o.Title.StartsWith(search));
            var rows = this.RenderView("rows", src.OrderBy(u => u.Id).Skip((page - 1) * ps).Take(ps));

            return Json(new { rows, more = src.Count() > page * ps });
        }
    }
}